package com.hliushi.controller;

import com.hliushi.domain.Blogger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;

/**
 * @ClassName ThymeleafController
 * @Description 测试404和500页面
 * @Author liushi
 * @Date 2020/9/16 20:30
 * @Version V1.0
 **/
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @GetMapping("/test404")
    public String test404() {
        return "index";
    }

    @GetMapping("/test500")
    public String test500() {
        int i = 1 / 0;
        return "index";
    }

    // 初始化一个Blogger对象,然后将该对象放在Model中,然后返回到blogger.html页面去渲染
    @GetMapping("/get/blogger")
    public String getBlogger(Model model) {
        Blogger blogger = new Blogger(1L, "Hliushi", "zidpass");
        model.addAttribute("blogger", blogger);
        return "blogger";
    }

    @GetMapping("/get/list")
    public String getList(Model model) {
        Blogger blogger = new Blogger(1L, "Hliushi", "zidpass");
        Blogger blogger1 = new Blogger(2L, "springandme", "pass");
        ArrayList<Blogger> list = new ArrayList<>();
        list.add(blogger);
        list.add(blogger1);
        model.addAttribute("list", list);
        return "list";
    }
}
